<template>
	<view class="person-detail-container">
		<uni-card :is-shadow="false" is-full>
			<text
				class="uni-h6">人脉即人际关系、人际网络、体现人的人缘、社会关系，通过各种渠道所达到的领域。根据辞典里的说法，人脉的解释为“经由人际关系而形成的人际脉络”，经常用于政治或商业的领域，但其实不论做什么行业，人人都会使用人脉。</text>
		</uni-card>
		<uni-section title="人脉信息" type="line">
			<view class="example">
				<!-- 基础用法，不包含校验规则 -->
				<uni-forms ref="baseForm" :modelValue="recordPerson">
					<uni-forms-item v-if="recordPerson.personType" label="类型:">
						<view class="detail-item">{{recordPerson.personType}}</view>
						<!-- <uni-data-select v-model="recordPerson.personType" :localdata="personRelationshipType"
							@change="change" label="应用选择">
						</uni-data-select> -->
					</uni-forms-item>
					<uni-forms-item v-if="recordPerson.name" label="姓名:">
						<view class="detail-item">{{recordPerson.name}}</view>
					</uni-forms-item>
					<uni-forms-item v-if="recordPerson.birthday" label="生日:">
						<view class="detail-item">{{recordPerson.birthday}}</view>
					</uni-forms-item>
					<uni-forms-item v-if="recordPerson.school" label="学校:">
						<view class="detail-item">{{recordPerson.school}}</view>
					</uni-forms-item>
					<uni-forms-item v-if="recordPerson.phoneNumber" label="电话:">
						<view class="detail-item">{{recordPerson.phoneNumber}}</view>
					</uni-forms-item>
					<uni-forms-item v-if="recordPerson.email" label="邮箱:">
						<view class="detail-item">{{recordPerson.email}}</view>
					</uni-forms-item>
					<uni-forms-item v-for="(item,index) in recordPerson.recordPersonExtensionList" v-if="item.content" :label="item.name+':'">
						<view class="detail-item">{{item.content}}</view>
					</uni-forms-item>
					<uni-forms-item v-if="recordPerson.remark" label="备注:">
						<view class="detail-item">{{recordPerson.remark}}</view>
					</uni-forms-item>
				</uni-forms>
			</view>
		</uni-section>
		<view class="button_box">
			<button class="uni-btn" type="warn" @click="deleteClick($event, recordPerson)">删除</button>
			<button class="uni-btn" type="primary" @click="callClick($event, recordPerson)">拨打</button>
		</view>
	</view>
</template>

<script>
	import {
		getPerson,
		deletePerson
	} from '@/api/record/person.js'
	
	import {
		getDictDataList
	} from '@/api/system/dict.js'
	export default {
		data() {
			return {
				recordPerson: {remark:{
					type:String,
					default:""
				}},
				dictQuery: {
					pageNum: 1,
					pageSize: 100,
					dictType: "person_relationship_type"
				}
			}
		},
		onLoad(event) {
			console.log("eventeventeventevent");
			console.log(event);
			this.getPersonDetail(event.personId);
		},
		methods: {
			getPersonDetail(id) {
				var that = this;
				getPerson(id).then(response => {
					console.log(response)
					that.recordPerson = response.data;
					getDictDataList(that.dictQuery).then(response => {
						var temp = response.rows;
						console.log("--getDictDataList--")
						console.log(temp)
						for (var i = 0; i < temp.length; i++) {
							console.log(temp[i].dictType)
							if(temp[i].dictValue == that.recordPerson.personType){
								that.recordPerson.personType = temp[i].dictLabel;
								break;
							}
						}
					});
				});
			},
			getDict() {
				var that = this;
			},
			
			callClick(e, item){
				uni.makePhoneCall({
					phoneNumber:item.phoneNumber,
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
						uni.showModal({
							title:"失败！"
						})
					},
					
				})
			},
			deleteClick(e, item){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '是否要删除该数据！',
					success: function (res) {
						if (res.confirm) {
							deletePerson(item.personId).then(response => {
								that.$tab.switchTab("/pages/work/index").then(()=>{
									uni.navigateTo({
										url: "/pages/package/work/person/index"
									});
								});
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	body, uni-app {
		background-color: white !important;
	}
	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}

	.detail-item {
		height: 100%;
		flex: auto;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}
	
	.button_box {
	    display: flex;
	    position: fixed;
	    bottom: 0;
	}
	
	.uni-btn {
		width: 375rpx;
		border-radius: 0;
	}
</style>
